<template>
  <div>
    <!-- 显示类 -->
    <el-table style="width: 100%; margin-top: 50px" border :data="list">
      <el-table-column
        type="index"
        label="序号"
        width="80px"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="sellerId"
        label="账号"
        width="150px"
      ></el-table-column>
      <el-table-column
        prop="sellerName"
        label="用户名"
        width="150px"
      ></el-table-column>
      <el-table-column prop="sellerAddress" label="地址" width="width">
      </el-table-column>
      <el-table-column
        prop="sellerPhone"
        label="电话"
        width="120px"
      ></el-table-column>
      <el-table-column prop="prop" label="操作" width="300px">
        <template slot-scope="{ row }">
          <a @click="deleteSeller(row.sellerId)">
            <el-button type="danger" icon="el-icon-delete"
              >删除该商家</el-button
            >
          </a>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      style="margin-top: 20px; text-align: center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="limit"
      layout="sizes, prev, pager, next, total"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
  
  <script>
export default {
  name: "Seller",

  data() {
    return {
      page: 1,
      limit: 5,
      total: 0,
      list: [],
    };
  },

  mounted() {
    this.getSellerList();
  },
  methods: {
    handleSizeChange(limit) {
      this.limit = limit;
      this.getSellerList();
    },
    handleCurrentChange(pager) {
      this.page = pager;
      this.getSellerList();
    },
    //获取所有用户
    async getSellerList() {
      const { page, limit } = this;
      let result = await this.$API.seller.reqSellerList(page, limit);
      if (result.code == 200) {
        this.total = result.data.total;
        this.list = result.data.sellerList;
      } else {
        return Promise.reject(new Error("false"));
      }
    },
    //删除商家
    async deleteSeller(sellerId) {
      if (confirm("删除商家会删除相关的数据,确定要删除该商家吗")) {
        let result = await this.$API.seller.reqAdminDeleteSeller(sellerId);
        if (result.code == 200) {
          this.getSellerList();
        } else {
          return Promise.reject(new Error("false"));
        }
      }
    },
  },
};
</script>
  
  <style lang="scss" scoped>
</style>